
import TextareaWithParamsV2 from '../../../components/TextareaWithParamsV2'
import { Radio, Input, Select } from 'antd'
import '../index.less'
import { useSourceOptions } from '@/pages/workflow/hooks/use-source-options'
import { CommonSmallSvg } from '@/pages/workflow/components/CommonSmallTemp'
import { CommmonSmallJudgmentCommon } from '@/pages/workflow/components/CommonSmallTemp'
import { CommonSmallErrorTitle } from '@/pages/workflow/components/CommonSmallTemp'
import { useEffect, useState } from 'react'
import { ARRAY } from '@/pages/workflow/constants'
const InputCont = ({ info, sourceOptions, editData }) => {
  const { options } = useSourceOptions(info, ["array_file", "array_string"])
  const [optionList, setOptionList] = useState([])
  useEffect(() => {
    if (Array.isArray(info.inputList) && info.inputList.length > 0) {
      const newList = info.inputList.map(item => ({
        ...item,
        value: item.value ? item.value : (item.valuet ? item.valuet : undefined), //解决迭代器的时候value重置问题
        value_selector: item.value_selector ? item.value_selector : (item.valuet  ?  item.valuet.split(',') : undefined),
      }))
      setOptionList(newList)
    } else {
      setOptionList([])
    }
  }, [info.inputList])

  return (
    <div className="flexCol InputCont_case">
      <div className="flexRowStart columns-title--dGaYetSzjjUdXN_u9_8J">
        <div className="input-head" style={{ width: '100px' }}>
          参数名称
        </div>
        {/* <div className="input-head w-[calc((100%-100px)*0.4)]">参数来源</div> */}
        <div className="input-head w-[calc((100%-100px))] ml-1">参数值</div>
      </div>
      {optionList.map((item, index) => (
        <div key={index} className="flexRowStart flexRowJustBet InputCont_marTop">
          <div className="flexRowStart flexRowJustBet w-[100%]">
            <div className="w-[100px]">
              <Input
                value={item.variable}
                onChange={e => {
                  const newList = optionList.map((obj, i) => {
                    if (index === i) {
                      return { ...obj, variable: e.target.value}
                    }
                    return obj
                  })
                  setOptionList(newList)
                  editData({
                    inputList: newList
                  })
                }}
                placeholder="参数名称"
              />
            </div>
            <div className="inputCont_end ml-1" style={{ width: 'calc(100% - 100px)' }}>
              {/* <Select
                className="w-[40%]"
                value={item.type}
                disabled
              >
                <Select.Option value="cite">引用</Select.Option>
              </Select> */}
              
              <CommmonSmallJudgmentCommon
                item={item}
                optionList={info.inputList}
                options={options}
                i={index}
                Change={ newList=> {
                  setOptionList(newList)
                  editData({inputList: newList})
                }}
                className='w-[100%]'
              />
            </div>
          </div>
        </div>
      ))}
     <CommonSmallErrorTitle
        optionList={optionList}
        noneList={['value', 'variable']}
        repeat={'variable'}
      />
    </div>
  )
}

export default InputCont